/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pie4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.pie4cloud.pie.bus.controller;

import com.pie4cloud.pie.bus.api.entity.DataKafConsumer;
import com.pie4cloud.pie.bus.service.KafkaManageService;
import com.pie4cloud.pie.common.core.util.R;
import com.pie4cloud.pie.common.security.annotation.Inner;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * kafka消费者管理
 *
 * @author pie code generator
 * @date 2021-12-28 10:59:58
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/datakafconsumer" )
@Api(value = "datakafconsumer", tags = "kafka消费者管理管理")
public class ApiKafkaManageController {

    private final KafkaManageService kafkaManageService;

    /**
     * 通过id查询kafka消费者管理
     * @param consId id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{consId}" )
	@Inner
    public R<DataKafConsumer> getById(@PathVariable("consId" ) Long consId) {
		DataKafConsumer consumer=null;
		try {
			consumer= kafkaManageService.getById(consId);
		} catch (Exception e) {
			return R.failed();
		}
		return R.ok(consumer);
    }

    /**
     * 新增kafka消费者管理
     * @param dataKafConsumer kafka消费者管理
     * @return R
     */
    @ApiOperation(value = "新增kafka消费者管理", notes = "新增kafka消费者管理")
    @PostMapping
	@Inner
    public R<DataKafConsumer> save(@RequestBody DataKafConsumer dataKafConsumer) {
		try {
			dataKafConsumer = kafkaManageService.saveAndSend(dataKafConsumer);
			if(null!=dataKafConsumer&&null!=dataKafConsumer.getConsId()){
				return R.ok(dataKafConsumer);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return R.failed();
    }

    /**
     * 修改kafka消费者管理
     * @param dataKafConsumer kafka消费者管理
     * @return R
     */
    @ApiOperation(value = "修改kafka消费者管理", notes = "修改kafka消费者管理")
    @PutMapping
	@Inner
    public R<DataKafConsumer> updateById(@RequestBody DataKafConsumer dataKafConsumer) {
		try {
			dataKafConsumer= kafkaManageService.editAndSend(dataKafConsumer);
		} catch (Exception e) {
			return R.failed();
		}
		return R.ok(dataKafConsumer);
    }

    /**
     * 通过id删除kafka消费者管理
     * @param consId id
     * @return R
     */
    @ApiOperation(value = "通过id删除kafka消费者管理", notes = "通过id删除kafka消费者管理")
    @DeleteMapping("/{consId}" )
    public R removeById(@PathVariable Long consId) {
		try {
			kafkaManageService.delAndSend(consId);
		} catch (Exception e) {
			return R.failed();
		}
		return R.ok();
    }

}
